<template>
	<view class="messagePage myBackground">
		<view class="content">
			<view class="mb15 pl10 pr10">
				<u-tabs :list="tabList" :current="current" :scrollable="true" lineColor="#3276FF" lineWidth="40"
					:activeStyle="{color: '#ffffff'}" :inactiveStyle="{color: '#ffffff'}" @change="tabsChange"></u-tabs>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @change="transition">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y class="h100p w100p">
						<view class="w100p pl15 pr15 d-flex-center boxSizing mb10">
							<view class="w100p d-flex a-center j-sb pt10 pb10 pl15 pr15 bgColor_jb bdr4"
								@click="openAllControlDialog()">
								<view class="fs14">
									<u-icon color="#ffffff" size="28" name="list-dot"></u-icon>
								</view>
								<view class="fs14 font_white">一键控制</view>
							</view>
						</view>

						<view class="d-flex flex-wrap a-center j-sb pl15 pr15">
							<view class="mb15" v-for="(item, index) in ktkgListData" :key="index"
								@click="popupOpenKtkzq(item, classroomData[index], '0')">
								<view class="content_item p15 boxSizing" :class="classroomDataBgColor[item.socketColor]">
									<view class="d-flex a-center j-sb">
										<view class="d-flex-center">
											<image style="width: 36px; height: 36px;" mode="aspectFill"
												src="/static/img/feature/children/kt.png"></image>
										</view>
										<view class="">
											<view class="rowValue">{{item.airTmp}} °C</view>
										</view>
									</view>
									<view class="mt10">
										<view class="rowName">{{classroomData[index]}}空调</view>
									</view>
								</view>
							</view>
						</view>
						<view style="height: 2rpx;"></view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y class="h100p w100p">
						<view class="w100p pl15 pr15 d-flex-center boxSizing mb10">
							<view class="w100p d-flex a-center j-sb pt10 pb10 pl15 pr15 bgColor_jb bdr4"
								@click="openAllControlDialog()">
								<view class="fs14">
									<u-icon color="#ffffff" size="28" name="list-dot"></u-icon>
								</view>
								<view class="fs14 font_white">一键控制</view>
							</view>
						</view>
						<view class="d-flex flex-wrap a-center j-sb pl15 pr15">
							<view class="mb15" v-for="(item, index) in czListData" :key="index"
								@click="popupOpen(item, classroomData[index], '1')">
								<view class="content_item p15 boxSizing" :class="classroomDataBgColor[item.socketColor]">
									<view class="d-flex">
										<view class="d-flex-center">
											<u--image :showLoading="true" src="http://36.138.43.18:8081/upload/269120244927134923.png"
												width="36px" height="36px"></u--image>
										</view>
									</view>
									<view class="mt10">
										<view class="rowName">{{classroomData[index]}}插座</view>
									</view>
								</view>
							</view>
						</view>
						<view style="height: 2rpx;"></view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y class="h100p w100p">
						<view class="w100p pl15 pr15 d-flex-center boxSizing mb10">
							<view class="w100p d-flex a-center j-sb pt10 pb10 pl15 pr15 bgColor_jb bdr4"
								@click="openAllControlDialog()">
								<view class="fs14">
									<u-icon color="#ffffff" size="28" name="list-dot"></u-icon>
								</view>
								<view class="fs14 font_white">一键控制</view>
							</view>
						</view>
						<view class="d-flex flex-wrap a-center j-sb pl15 pr15">
							<view class="mb15" v-for="(item, index) in zmListData" :key="index"
								@click="popupOpen(item, classroomData2[index], '2')">
								<view class="content_item p15 boxSizing" :class="classroomDataBgColor[item.socketColor]">
									<view class="d-flex">
										<view class="d-flex-center">
											<u--image :showLoading="true" src="http://36.138.43.18:8081/upload/881920244927134952.png"
												width="36px" height="36px"></u--image>
										</view>
									</view>
									<view class="mt10">
										<view class="rowName">{{classroomData2[index]}}照明</view>
									</view>
								</view>
							</view>
						</view>
						<view style="height: 2rpx;"></view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y class="h100p w100p">
						<view class="w100p pl15 pr15 d-flex-center boxSizing mb10">
							<view class="w100p d-flex a-center j-sb pt10 pb10 pl15 pr15 bgColor_jb bdr4"
								@click="openAllControlDialog()">
								<view class="fs14">
									<u-icon color="#ffffff" size="28" name="list-dot"></u-icon>
								</view>
								<view class="fs14 font_white">一键控制</view>
							</view>
						</view>
						<view class="d-flex flex-wrap a-center j-sb pl15 pr15">
							<view class="mb15" v-for="(item, index) in ggqyListData" :key="index"
								@click="popupOpen(item, ggqyTitleListData[index], '3')">
								<view class="content_item p15 boxSizing" :class="classroomDataBgColor[item.socketColor]">
									<view class="d-flex">
										<view class="d-flex-center">
											<u--image :showLoading="true" :src="ggqyIconListData[index]" width="36px"
												height="36px"></u--image>
										</view>
									</view>
									<view class="mt10">
										<view class="rowName">{{ggqyTitleListData[index]}}</view>
									</view>
								</view>
							</view>
						</view>
						<view style="height: 2rpx;"></view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y class="h100p w100p">
						<view class="w100p pl15 pr15 d-flex-center boxSizing mb10">
							<view class="w100p d-flex a-center j-sb pt10 pb10 pl15 pr15 bgColor_jb bdr4"
								@click="openAllControlDialog()">
								<view class="fs14">
									<u-icon color="#ffffff" size="28" name="list-dot"></u-icon>
								</view>
								<view class="fs14 font_white">一键控制</view>
							</view>
						</view>
						<view class="d-flex flex-wrap a-center j-sb pl15 pr15">
							<view class="mb15" v-for="(item, index) in ktListData" :key="index"
								@click="popupOpen(item, classroomData[index], '4')">
								<view class="content_item p15 boxSizing" :class="classroomDataBgColor[item.socketColor]">
									<view class="d-flex">
										<view class="d-flex-center">
											<u--image :showLoading="true" src="http://36.138.43.18:8081/upload/799320245027135044.png"
												width="36px" height="36px"></u--image>
										</view>
									</view>
									<view class="mt10">
										<view class="rowName">{{classroomData[index]}}空调开关</view>
									</view>
								</view>
							</view>
						</view>
						<view style="height: 2rpx;"></view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y class="h100p w100p">
						<view class="d-flex flex-wrap a-center j-sb pl15 pr15">
							<view class="mb15" v-for="(item, index) in fjzkListData" :key="index"
								@click="popupOpen(item, classroomData3[index], '5')">
								<view class="content_item p15 boxSizing" :class="classroomDataBgColor[item.socketColor]">
									<view class="d-flex">
										<view class="d-flex-center">
											<u--image :showLoading="true" src="http://36.138.43.18:8081/upload/799320245027135044.png"
												width="36px" height="36px"></u--image>
										</view>
									</view>
									<view class="mt10">
										<view class="rowName">{{classroomData3[index]}}总控</view>
									</view>
								</view>
							</view>
						</view>
						<view style="height: 2rpx;"></view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y class="h100p w100p">
						<view class="d-flex flex-wrap a-center j-sb pl15 pr15">
							<view class="mb15" v-for="(item, index) in pdxzkListData" :key="index"
								@click="popupOpen(item, classroomData4[index], '6')">
								<view class="content_item p15 boxSizing" :class="classroomDataBgColor[item.socketColor]">
									<view class="d-flex">
										<view class="d-flex-center">
											<u--image :showLoading="true" src="http://36.138.43.18:8081/upload/799320245027135044.png"
												width="36px" height="36px"></u--image>
										</view>
									</view>
									<view class="mt10">
										<view class="rowName">{{classroomData4[index]}}配电箱总控</view>
									</view>
								</view>
							</view>
						</view>
						<view style="height: 2rpx;"></view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>

		<u-popup :customStyle="{width: '680rpx'}" :show="popupShow" mode="center" :round="10" @close="popupShow = false">
			<view class="p15">
				<view class="">
					<view class="d-flex-center fs16 fw600">控制</view>
					<view class="">
						<view>
							<u-checkbox-group v-model="checkboxValue1" @change="checkboxChange1" placement="column">
								<u-checkbox :customStyle="{marginBottom: '10px'}" label="房间" name="房间">
								</u-checkbox>
							</u-checkbox-group>
						</view>
						<u-checkbox-group class="d-flex flex-wrap a-center pl15" v-model="checkboxValue2" placement="column"
							@change="checkboxChange2">
							<u-checkbox :customStyle="{marginBottom: '30rpx',marginRight: '40rpx'}"
								v-for="(item, index) in allControlData" :key="index" :label="item.deviceName" :name="item.deviceCode">
							</u-checkbox>
						</u-checkbox-group>
						<view class="fs14 mb10">操作类型</view>
						<view class="d-flex a-center mb20" v-if="swiperCurrent=='0'">
							<view class="fs14">模式：</view>
							<view class="flex-1">
								<uni-data-select v-model="selectValue" :localdata="selectData" @change="selectChange"></uni-data-select>
							</view>
						</view>
						<view class="d-flex a-center mb20" v-else>
							<view class="fs14">模式：</view>
							<view class="flex-1 mt5">
								<u-radio-group v-model="radioValue" placement="row">
									<u-radio v-for="(item,index) in operateTypeData" :key="index" :label="item.text" :name="item.value"
										:customStyle="{marginRight: '40rpx'}"></u-radio>
								</u-radio-group>
							</view>
						</view>
						<view class="d-flex a-center j-sa">
							<view class="w40p">
								<u-button size="small" text="取消" @click="popupShow = false"></u-button>
							</view>
							<view class="w40p">
								<u-button size="small" :loading="addOrUpdateLoading" type="primary" text="确定"
									@click="allSaveControl()"></u-button>
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>

		<u-picker :show="pickerShow" :title="pickerTitle" ref="uPicker" :columns="pickerColumns" :defaultIndex="[0,0]"
			keyName="commandName" @confirm="pickerConfirm" @close="closePicker" @cancel="closePicker"
			@change="changeHandler"></u-picker>

		<u-modal :show="modalShow1" :title="modalTitle1" :content='modalContent1' :showConfirmButton="true"
			:showCancelButton="true" @confirm="modalConfirm" @cancel="modalShow1 = false"></u-modal>

		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		queryOneListControlByAppStatus,
		queryTwoListControlByAppStatus,
		queryThreeListControlByAppStatus,
		queryFourListControlByAppStatus,
		queryFiveListControlByAppStatus,
		querySixListControlByAppStatus,
		querySevenListControlByAppStatus,
		queryEightListControlByAppStatus
	} from "@/api/dormBuilding/oneBuildFiveFloor.js"

	import {
		queryControlListByApp,
		makeDeviceControlByApp,
		queryControlListV3ByApp,
		batchControlByApp
	} from "@/api/index.js"

	import {
		dormOneBuildingFiveFloorDevice
	} from "@/settings"

	export default {
		data() {
			return {
				userInfo: {},
				timeout: [],

				swiperCurrent: 0,
				current: 0,

				tabList: [{
					name: '空调控制'
				}, {
					name: '插座控制'
				}, {
					name: '照明控制'
				}, {
					name: '公共区控制'
				}, {
					name: '空调开关控制'
				}, {
					name: '房间总控'
				}, {
					name: '房间配电箱总控'
				}],

				classroomData: ['1501室', '1502室', '1503室', '1504室', '1505室', '1506室', '1507室', '1508室', '1509室',
					'1510室', '1511室', '1512室', '1513室', '1515室', '1516室', '1517室', '1518室', '宿管间'
				],
				classroomData2: ['1501-1506室', '1507-1513室', '1515室', '1516室', '1517室', '1518室', '宿管间'],
				classroomDataBgColor: ['bgColor_info', 'bgColor_success', 'bgColor_danger', 'bgColor_blue',
					'bgColor_warning', 'bgColor_red', 'bgColor_orange'
				],

				ktkgListData: [],
				czListData: [],
				zmListData: [],
				zkgListData: [],
				ggqyListData: [],
				fjzkListData: [],
				pdxzkListData: [],
				classroomData3: ['1514室', '1515室', '1516室', '1517室', '1518室'],
				classroomData4: ['1514室', '1515室', '1516室', '1517室', '1518室'],

				ggqyTitleListData: ['东过道照明开关1', '东过道照明开关2', '西过道照明开关', '应急灯开关', '饮水机开关', '洗衣机开关'],
				ggqyIconListData: [
					'http://36.138.43.18:8081/upload/222220245527135506.png',
					'http://36.138.43.18:8081/upload/222220245527135506.png',
					'http://36.138.43.18:8081/upload/222220245527135506.png',
					'http://36.138.43.18:8081/upload/741420245427135437.png',
					'http://36.138.43.18:8081/upload/423820245427135458.png',
					'http://36.138.43.18:8081/upload/382120245427135447.png'
				],
				ktListData: [],

				dataItem: {},

				popupShow: false,
				addOrUpdateLoading: false,
				allControlData: [],
				checkboxValue1: [],
				checkboxValue2: [],
				selectValue: "",
				selectData: [],

				operateTypeData: [{
						value: '65365',
						text: '合闸',
						parameterCode: 'CTRL',
					},
					{
						value: '65280',
						text: '分闸',
						parameterCode: 'CTRL',
					}
				],
				radioValue: "",

				modalShow1: false,
				modalTitle1: "",
				modalContent1: "",
				apiObj: {},

				pickerShow: false,
				pickerTitle: "",
				pickerColumns: [],
				allColumnData: []
			};
		},
		created() {
			this.userInfo = uni.getStorageSync('userInfo')
		},
		mounted() {
			this.queryOneListControlByAppStatus()
			this.queryTwoListControlByAppStatus()
			this.queryThreeListControlByAppStatus()
			// this.queryFourListControlByAppStatus()
			this.queryFiveListControlByAppStatus()
			this.querySixListControlByAppStatus()
			this.querySevenListControlByAppStatus()
			this.queryEightListControlByAppStatus()

			this.setupTimer()
		},
		methods: {
			// 设置定时器
			setupTimer() {
				let _this = this;
				_this.timeout[0] = setInterval(() => {
					_this.queryOneListControlByAppStatus()
					_this.queryTwoListControlByAppStatus()
					_this.queryThreeListControlByAppStatus()
					// _this.queryFourListControlByAppStatus()
					_this.queryFiveListControlByAppStatus()
					_this.querySixListControlByAppStatus()
					_this.querySevenListControlByAppStatus()
					_this.queryEightListControlByAppStatus()
				}, 7000);
			},
			// 清除定时器
			clearTimer() {
				let _this = this;
				if (_this.timeout.length > 0) {
					_this.timeout.forEach(item => {
						clearInterval(item);
					})
				}
			},

			async queryOneListControlByAppStatus() {
				const that = this
				await queryOneListControlByAppStatus().then(res => {
					let tempData = res.object || []
					that.ktkgListData = tempData
				})
			},
			async queryTwoListControlByAppStatus() {
				await queryTwoListControlByAppStatus().then(res => {
					let tempData = res.object || []
					this.czListData = tempData
				})
			},
			async queryThreeListControlByAppStatus() {
				await queryThreeListControlByAppStatus().then(res => {
					let tempData = res.object || []
					this.zmListData = tempData
				})
			},
			async queryFourListControlByAppStatus() {
				await queryFourListControlByAppStatus().then(res => {
					let tempData = res.object || []
					this.zkgListData = tempData
				})
			},
			async queryFiveListControlByAppStatus() {
				await queryFiveListControlByAppStatus().then(res => {
					let tempData = res.object || []
					this.ggqyListData = tempData
				})
			},
			async querySixListControlByAppStatus() {
				await querySixListControlByAppStatus().then(res => {
					let tempData = res.object || []
					this.ktListData = tempData
				})
			},

			async querySevenListControlByAppStatus() {
				await querySevenListControlByAppStatus().then(res => {
					let tempData = res.object || []
					this.fjzkListData = tempData
				})
			},

			async queryEightListControlByAppStatus() {
				await queryEightListControlByAppStatus().then(res => {
					let tempData = res.object || []
					this.pdxzkListData = tempData
				})
			},

			// 空调控制器
			popupOpenKtkzq(data, roomName, type) {
				this.pickerTitle = roomName + "空调"

				this.dataItem = data
				this.pickerColumns = []
				this.allColumnData = []

				this.queryControlListByApp(data)
				this.clearTimer()

				this.pickerShow = true
			},
			closePicker() {
				this.pickerShow = false
				this.setupTimer()
			},
			async queryControlListByApp(data) {
				await queryControlListByApp({
					deviceCode: data.deviceCode
				}).then(res => {
					let tempData = res.object || []

					let arrData = []
					let arrOneData = [
						[],
						[]
					]
					let arrTwoData = [
						[],
						[],
						[],
					]
					for (var i = 0; i < tempData.length; i++) {
						let obj = {
							commandName: tempData[i].name,
							command: (new Date().getTime()).toString(),
							parameterCode: (new Date().getTime()).toString(),
						}
						arrOneData[0].push(obj)

						if (i == 0) {
							for (var j = 0; j < tempData[i].list.length; j++) {
								let obj = {
									commandName: tempData[i].list[j].commandName,
									command: tempData[i].list[j].command,
									parameterCode: tempData[i].list[j].parameterCode
								}
								arrOneData[1].push(obj)
								arrTwoData[0].push(obj)
							}
						}
						if (i == 1) {
							for (var j = 0; j < tempData[i].list.length; j++) {
								let obj = {
									commandName: tempData[i].list[j].commandName,
									command: tempData[i].list[j].command,
									parameterCode: tempData[i].list[j].parameterCode
								}
								arrTwoData[1].push(obj)
							}
						}
						if (i == 2) {
							for (var j = 0; j < tempData[i].list.length; j++) {
								let obj = {
									commandName: tempData[i].list[j].commandName,
									command: tempData[i].list[j].command,
									parameterCode: tempData[i].list[j].parameterCode
								}
								arrTwoData[2].push(obj)
							}
						}
					}

					this.pickerColumns = arrOneData
					this.allColumnData = arrTwoData
				})
			},

			changeHandler(e) {
				const {
					columnIndex,
					value,
					values, // values为当前变化列的数组内容
					index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
					picker = this.$refs.uPicker
				} = e

				// 当第一列值发生变化时，变化第二列(后一列)对应的选项
				if (columnIndex === 0) {
					// picker为选择器this实例，变化第二列对应的选项
					picker.setColumnValues(1, this.allColumnData[index])
				}
			},
			pickerConfirm(e) {
				let that = this
				let obj = {
					userCode: this.userInfo.userCode,
					userName: this.userInfo.userName,
					deviceCode: this.dataItem.deviceCode,
					parameterCode: e.value[1].parameterCode,
					command: e.value[1].command,
					commandName: e.value[1].commandName,
				}
				that.pickerShow = false
				this.setupTimer()
				makeDeviceControlByApp(obj).then(res => {
					if (res.status == 200 && (res.message == '指令发送成功' || res.message == '指令发送成功等待核验')) {
						that.$refs.uToast.show({
							type: 'loading',
							title: '正在加载',
							message: "正在加载",
							iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/loading.png',
							duration: 2000,
							complete() {
								that.queryOneListControlByAppStatus()
								uni.showToast({
									duration: 1000,
									icon: "success",
									title: "指令发送成功"
								})
							}
						})
					}
				})
			},

			// 开关和分闸
			popupOpen(data, roomName, type) {
				this.dataItem = data

				let tempTitle = ""
				switch (type) {
					case '0':
						tempTitle = roomName + "空调"
						break;
					case "1":
						tempTitle = roomName + "插座"
						break;
					case '2':
						tempTitle = roomName + "照明"
						break;
					case "3":
						tempTitle = roomName
						break;
					case '4':
						tempTitle = roomName + "空调开关"
						break;
					case "5":
						tempTitle = roomName + "总控"
						break;
					case "6":
						tempTitle = roomName + "配电箱总控"
						break;
					default:
						tempTitle = roomName
						break;
				}
				this.modalTitle1 = tempTitle

				let obj = {}
				if (data.deviceList[data.deviceList.length - 2].deviceValue == '0') {
					obj = {
						command: '65365',
						commandName: '合闸',
						parameterCode: 'CTRL',
					}
					this.modalContent1 = "确定执行合闸操作吗, 是否继续?"
				} else {
					obj = {
						command: '65280',
						commandName: '分闸',
						parameterCode: 'CTRL',
					}
					this.modalContent1 = "确定执行分闸操作吗, 是否继续?"
				}
				this.apiObj = obj

				this.modalShow1 = true
			},
			modalConfirm(e) {
				let that = this

				let obj = {
					userCode: this.userInfo.userCode,
					userName: this.userInfo.userName,
					deviceCode: this.dataItem.deviceCode,
					parameterCode: this.apiObj.parameterCode,
					command: this.apiObj.command,
					commandName: this.apiObj.commandName,
				}

				that.modalShow1 = false

				makeDeviceControlByApp(obj).then(res => {
					if (res.status == 200 && (res.message == '指令发送成功' || res.message == '指令发送成功等待核验')) {

						that.$refs.uToast.show({
							type: 'loading',
							title: '正在加载',
							message: "正在加载",
							iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/loading.png',
							duration: 2000,
							complete() {
								if (that.current == 1) {
									that.queryTwoListControlByAppStatus()
								} else if (that.current == 2) {
									that.queryThreeListControlByAppStatus()
								} else if (that.current == 3) {
									that.queryFiveListControlByAppStatus()
								} else if (that.current == 4) {
									that.querySixListControlByAppStatus()
								} else if (that.current == 5) {
									that.querySevenListControlByAppStatus()
								} else if (that.current == 6) {
									that.queryEightListControlByAppStatus()
								}

								uni.showToast({
									duration: 1000,
									icon: "success",
									title: "指令发送成功"
								})
							}
						})
					}
				})
			},

			openAllControlDialog() {
				if (this.swiperCurrent == '0') {
					this.allControlData = dormOneBuildingFiveFloorDevice.kt
				} else if (this.swiperCurrent == '1') {
					this.allControlData = dormOneBuildingFiveFloorDevice.cz
				} else if (this.swiperCurrent == '2') {
					this.allControlData = dormOneBuildingFiveFloorDevice.zm
				} else if (this.swiperCurrent == '3') {
					this.allControlData = dormOneBuildingFiveFloorDevice.ggqy
				} else if (this.swiperCurrent == '4') {
					this.allControlData = dormOneBuildingFiveFloorDevice.ktkg
				}

				this.checkboxValue1 = []
				this.checkboxValue2 = []
				this.selectValue = ""
				this.radioValue = ""
				this.addOrUpdateLoading = false

				this.popupShow = true

				this.queryControlListV3ByApp()
			},
			queryControlListV3ByApp() {
				queryControlListV3ByApp({
					deviceCode: 'DEVC2407258259342'
				}).then(res => {
					let tempData = res.object[0].list

					let arrData = []
					for (var i = 0; i < tempData.length; i++) {
						let objData = {
							parameterCode: tempData[i].parameterCode,
							value: tempData[i].command,
							text: tempData[i].commandName,
						}
						arrData.push(objData)
					}

					this.selectData = arrData
				})
			},
			popupClose() {
				console.log('popupClose');
				this.popupShow = false
			},
			// 全选
			checkboxChange1(val) {
				if (val.length == 1) {
					this.checkboxValue2 = this.allControlData.map(item => {
						return item.deviceCode
					})
				} else {
					this.checkboxValue2 = []
				}
			},
			// 多选
			checkboxChange2(val) {
				let len1 = val.length
				let len2 = this.allControlData.length
				if (len1 == len2) {
					this.checkboxValue1 = ['房间']
				} else {
					this.checkboxValue1 = []
				}
			},
			selectChange(e) {
				console.log("e:", e);
			},
			allSaveControl() {
				const _this = this
				if (_this.checkboxValue2.length == 0) {
					uni.showToast({
						duration: 1000,
						icon: "error",
						title: '请选择房间'
					})
					return
				}

				if (_this.swiperCurrent == '0') {
					if (!_this.selectValue) {
						uni.showToast({
							duration: 1000,
							icon: "error",
							title: '请选择模式'
						})
						return
					}
				} else {
					if (!_this.radioValue) {
						uni.showToast({
							duration: 1000,
							icon: "error",
							title: '请选择模式'
						})
						return
					}
				}
				let objData = {}
				if (_this.swiperCurrent == '0') {
					objData = _this.selectData.find(item => {
						return item.value == _this.selectValue
					})
				} else {
					objData = _this.operateTypeData.find(item => {
						return item.value == _this.radioValue
					})
				}

				this.addOrUpdateLoading = true
				_this.popupShow = false

				batchControlByApp({
					deviceCodes: _this.checkboxValue2.join("&"),
					parameterCode: objData.parameterCode,
					command: objData.value,
					commandName: objData.text,
					userCode: _this.userInfo.userCode,
					userName: _this.userInfo.userName,
				}).then(res => {
					if (res.status == '200') {

						_this.$refs.uToast.show({
							type: 'loading',
							title: '正在加载',
							message: "正在加载",
							iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/loading.png',
							duration: 2000,
							complete() {
								if (_this.current == 0) {
									_this.queryOneListControlByAppStatus()
								} else if (_this.current == 1) {
									_this.queryTwoListControlByAppStatus()
								} else if (_this.current == 2) {
									_this.queryThreeListControlByAppStatus()
								} else if (_this.current == 3) {
									_this.queryFourListControlByAppStatus()
								} else if (_this.current == 4) {
									_this.queryFiveListControlByAppStatus()
								} else if (_this.current == 5) {
									_this.querySixListControlByAppStatus()
								}

								uni.showToast({
									duration: 1000,
									icon: "success",
									title: "指令发送成功"
								})

								_this.addOrUpdateLoading = false
							}
						})
					} else {
						this.addOrUpdateLoading = false
					}
				})
			},

			// tabs通知swiper切换
			tabsChange(e) {
				this.current = e.index;
				this.swiperCurrent = e.index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				this.current = e.detail.current
				this.swiperCurrent = e.detail.current
			},

			goPage(url) {
				uni.navigateTo({
					url
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f5f5;
	}

	.messagePage {
		height: calc(100vh - var(--window-top));
		width: 100%;

		.content {
			display: flex;
			flex-direction: column;
			height: calc(100% - 20rpx);
			font-family: Source Han Sans CN, Source Han Sans CN-400;

			.swiper-box {
				flex: 1;
			}

			.swiper-item {
				height: 100%;
			}

			.bgColor_info {
				background: #787878;
			}

			.bgColor_success {
				background: #1BBC7C;
			}

			.bgColor_danger {
				background: #AD5679;
			}

			.bgColor_blue {
				background: #5589F2;
			}

			.bgColor_warning {
				background: #E8CB58;
			}

			.bgColor_red {
				background: #E14B4B;
			}

			.bgColor_orange {
				background: #E46F1C;
			}

			.bgColor_jb {
				background: linear-gradient(90deg, #1bbcb4, #638aed 100%);
			}

			.bgColor_blue2 {
				background: #4651f2;
			}

			.font_white {
				color: #ffffff;
			}

			.content_item {
				width: 334rpx;
				border-radius: 16rpx;
				box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.10);

				.icon-kaiguan-kai {
					color: #5589F2;
				}

				.rowName {
					font-size: 32upx;
					color: #ffffff;
					font-family: Source Han Sans CN, Source Han Sans CN-400;
				}

				.rowValue {
					font-size: 28upx;
					color: #ffffff;
				}
			}
		}
	}
</style>